package cn.caskm.souvenirshopsystem.controller.admin;

import cn.caskm.souvenirshopsystem.domain.Result;
import cn.caskm.souvenirshopsystem.domain.dto.PageDTO;
import cn.caskm.souvenirshopsystem.domain.dto.StudentUserRegisterDTO;
import cn.caskm.souvenirshopsystem.domain.dto.StudentUserUpdateDTO;
import cn.caskm.souvenirshopsystem.domain.query.StudentUserQuery;
import cn.caskm.souvenirshopsystem.domain.vo.StudentUserVO;
import cn.caskm.souvenirshopsystem.enums.StatusEnum;
import cn.caskm.souvenirshopsystem.service.StudentUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/studentUser")
@RequiredArgsConstructor
public class AdminStudentUserController {

    private final StudentUserService studentUserService;

    @GetMapping("/page")
    public Result<PageDTO<StudentUserVO>> page(StudentUserQuery query) {
        return studentUserService.page(query);
    }

    @GetMapping("/detail/{id}")
    public Result<StudentUserVO> getDetail(@PathVariable("id") Integer id) {
        return studentUserService.getStudentUserDetail(id);
    }

    @PostMapping("/create")
    public Result<Void> createStudentUser(@RequestBody StudentUserRegisterDTO registerDTO) {
        return studentUserService.register(registerDTO);
    }

    @PutMapping("/update")
    public Result<Void> updateStudentUser(@RequestBody StudentUserUpdateDTO updateDTO) {
        return studentUserService.updateStudentUser(updateDTO);
    }

    @DeleteMapping("/{id}")
    public Result<Void> deleteStudentUser(@PathVariable("id") Integer id) {
        return studentUserService.deleteStudentUser(id);
    }

    @PutMapping("/updateStatus/{id}")
    public Result<Void> updateStatus(@PathVariable("id") Integer id,
                                   @RequestParam("status") StatusEnum status) {
        return studentUserService.updateStatus(id, status);
    }

    @PutMapping("/updateVipLevel/{id}")
    public Result<Void> updateVipLevel(@PathVariable("id") Integer id,
                                     @RequestParam("vipLevel") Integer vipLevel) {
        return studentUserService.updateVipLevel(id, vipLevel);
    }

    @GetMapping("/getByStudentNo/{sno}")
    public Result<StudentUserVO> getByStudentNo(@PathVariable("sno") String sno) {
        return studentUserService.getByStudentNo(sno);
    }

}
